package com.orm.analysis.dao.impl;

import com.orm.analysis.dao.GenericJPADAO;
import com.orm.analysis.model.Check;
import com.orm.analysis.model.CreditCard;
import com.orm.analysis.model.Payment;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.Query;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: saman
 * Date: 10/12/13
 * Time: 2:17 PM
 * To change this template use File | Settings | File Templates.
 */
public class CheckDAO extends GenericJPADAO<Check, Integer>  {

    public List<Check> list(int page, int size) {
              Query query = this.em.createQuery("Select a from Payment a where a.paymentType=:paymode");
              query.setParameter("paymode","CHECK");
              query.setFirstResult((page - 1) * size);
              query.setMaxResults(size);
              return query.getResultList();
          }


          public Check getById(Integer id) {
                return this.em.find(Check.class,id);
          }

       @Transactional
                    @Override
                    public void save(Check entity) {
                         getEntityManager().persist(entity);
                    }

    @Transactional
                 @Override
                     public void delete(Object id) {
                         getEntityManager().remove(getEntityManager().find(Check.class, id));

                      }
}
